package com.lxd.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.lxd.entity.enums.PageSize;
import com.lxd.entity.query.MemberQuery;
import com.lxd.entity.po.Member;
import com.lxd.entity.vo.PaginationResultVO;
import com.lxd.entity.query.SimplePage;
import com.lxd.mappers.MemberMapper;
import com.lxd.service.MemberService;
import com.lxd.utils.StringTools;


/**
 *  业务接口实现
 */
@Service("memberService")
public class MemberServiceImpl implements MemberService {

	@Resource
	private MemberMapper<Member, MemberQuery> memberMapper;

	/**
	 * 根据条件查询列表
	 */
	@Override
	public List<Member> findListByParam(MemberQuery param) {
		return this.memberMapper.selectList(param);
	}

	/**
	 * 根据条件查询列表
	 */
	@Override
	public Integer findCountByParam(MemberQuery param) {
		return this.memberMapper.selectCount(param);
	}

	/**
	 * 分页查询方法
	 */
	@Override
	public PaginationResultVO<Member> findListByPage(MemberQuery param) {
		int count = this.findCountByParam(param);
		int pageSize = param.getPageSize() == null ? PageSize.SIZE15.getSize() : param.getPageSize();

		SimplePage page = new SimplePage(param.getPageNo(), count, pageSize);
		param.setSimplePage(page);
		List<Member> list = this.findListByParam(param);
		PaginationResultVO<Member> result = new PaginationResultVO(count, page.getPageSize(), page.getPageNo(), page.getPageTotal(), list);
		return result;
	}

	/**
	 * 新增
	 */
	@Override
	public Integer add(Member bean) {
		return this.memberMapper.insert(bean);
	}

	/**
	 * 批量新增
	 */
	@Override
	public Integer addBatch(List<Member> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.memberMapper.insertBatch(listBean);
	}

	/**
	 * 批量新增或者修改
	 */
	@Override
	public Integer addOrUpdateBatch(List<Member> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.memberMapper.insertOrUpdateBatch(listBean);
	}

	/**
	 * 多条件更新
	 */
	@Override
	public Integer updateByParam(Member bean, MemberQuery param) {
		StringTools.checkParam(param);
		return this.memberMapper.updateByParam(bean, param);
	}

	/**
	 * 多条件删除
	 */
	@Override
	public Integer deleteByParam(MemberQuery param) {
		StringTools.checkParam(param);
		return this.memberMapper.deleteByParam(param);
	}

	/**
	 * 根据Id获取对象
	 */
	@Override
	public Member getMemberById(Long id) {
		return this.memberMapper.selectById(id);
	}

	/**
	 * 根据Id修改
	 */
	@Override
	public Integer updateMemberById(Member bean, Long id) {
		return this.memberMapper.updateById(bean, id);
	}

	/**
	 * 根据Id删除
	 */
	@Override
	public Integer deleteMemberById(Long id) {
		return this.memberMapper.deleteById(id);
	}
}